const HOST = 'https://api.darwinedu.com';
const HTML_HOST = "https://api.darwinedu.com";
const md5Key = "birddapp";

//console.log("imei:"+plus.device.imei);
var init_require_params = {
	imei: "h5",
	version: "8.8.8",
	appid: "h5",
	device: "h5 browser"
};
//#ifdef APP-PLUS
var imei_global = plus.device.imei != " " ? plus.device.imei : plus.device.uuid;
var app_version_global = plus.runtime.version;
var appid_global = plus.runtime.appid;
var device_global = plus.os.name;
var nonce_str = Math.random();

init_require_params = {
	imei: imei_global,
	version: app_version_global,
	appid: appid_global,
	device: device_global
}
//#endif
const require_params = init_require_params;

const API = {
	login_verifyimg: HOST + "/dapp/user/verifyimg",
	sendsms: HOST + "/dapp/user/sendsms", //表单提交类接口
	login: HOST + "/dapp/user/login", //表单提交类接口
	register: HOST + "/dapp/user/reg", //表单提交类接口
	findpass: HOST + "/dapp/user/findpass", //表单提交类接口
	realnameApply: HOST + "/dapp/ucenter/realnameApply", //表单提交类接口
	userInfo: HOST + "/dapp/ucenter/userInfo",
	scoreGoods: HOST + "/dapp/shop/scoregoods",
	rmbGoods: HOST + "/dapp/shop/rmbgoods",
	shop_getGoods: HOST + "/dapp/shop/getGoods",
	getPaopaoData: HOST + "/dapp/home/getPaopaoData",
	getOpenWalletText: HOST + "/dapp/ucenter/getOpenWalletText",
	applyWallet: HOST + "/dapp/ucenter/applyWallet", //表单提交类接口
	checkIn: HOST + "/dapp/checkIn/checkin", //表单提交类接口
	isCheckIn: HOST + "/dapp/checkIn/isCheckin",
	clickPaopao: HOST + "/dapp/home/clickPaopao", //表单提交类接口
	getRmbShopBanner: HOST + "/dapp/shop/rmbBanner",
	getUserAddress: HOST + "/dapp/order/getUserAddress",
	saveUserAddress: HOST + "/dapp/order/saveUserAddress", //表单提交类接口
	getUserAddressList: HOST + "/dapp/order/getUserAddressList",
	deleteUserAddress: HOST + "/dapp/order/deleteUserAddress",
	setUserAddressDefault: HOST + "/dapp/order/setUserAddressDefault",
	getUserAddressById: HOST + "/dapp/order/getUserAddressById",
	//兑换商城创建订单
	createOrder: HOST + "/dapp/order/createOrder", //表单提交类接口
	getOrder: HOST + "/dapp/order/getOrder",
	shop_confirmorder: HOST + "/dapp/order/confirmorder", //表单提交类接口
	shop_getRecommendSearchKey: HOST + "/dapp/shop/getRecommendSearchKey",
	orderList: HOST + "/dapp/order/orderList",
	getQrcode: HOST + "/dapp/qrcode/getQrcode",
	getUserScore: HOST + "/dapp/ucenter/getUserScore",
	setPassword: HOST + "/dapp/ucenter/reSetPassword", //表单提交类接口
	scoreLog: HOST + "/dapp/ucenter/scoreLog",
	getSuanliBuy: HOST + "/dapp/suanli/getSuanliBuy",
	buySuanli: HOST + "/dapp/suanli/buySuanli", //表单提交类接口
	getSuanliBuyLog: HOST + "/dapp/suanli/getSuanliBuyLog",
	bindWechat: HOST + "/dapp/ucenter/bindWechat", //表单提交类接口
	inviteUsersInfo: HOST + "/dapp/ucenter/inviteUsersInfo",
	inviteUsers: HOST + "/dapp/ucenter/inviteUsers",
	checkOrderStatus: HOST + "/dapp/home/checkOrderStatus",
	tradeOrderList: HOST + "/dapp/trade/tradeOrderList",
	tradeSellOrderList: HOST + "/dapp/trade/tradeSellOrderList",
	tradeDealLists: HOST + "/dapp/trade/dealLists",
	tradeOrderLists: HOST + "/dapp/trade/orderLists",
	initCreateOrder: HOST + "/dapp/trade/initCreateOrder",
	tradeCreateOrder: HOST + "/dapp/trade/createOrder",
	getLastPrice: HOST + "/dapp/trade/getLastPrice",
	createOrderLog: HOST + "/dapp/trade/createOrderLog",
	getTradeOrderLog: HOST + "/dapp/trade/getTradeOrderLog",
	cancelTradeOrderLog: HOST + "/dapp/trade/cancelTradeOrderLog",
	cancelTradeOrder: HOST + "/dapp/trade/cancelTradeOrder", //表单提交类接口
	setFinishPayTradeOrderLog: HOST + "/dapp/trade/setFinishPayTradeOrderLog", //表单提交类接口
	getTradeOrder: HOST + "/dapp/trade/getTradeOrder",
	confirmSendTradeOrder: HOST + "/dapp/trade/confirmSendTradeOrder", //表单提交类接口
	tradeOrderShensu: HOST + "/dapp/trade/tradeOrderShensu",
	trade_cancelTradeOrderShensu: HOST + "/dapp/trade/cancelTradeOrderShensu", //表单提交类接口
	trade_kline: HOST + "/dapp/trade/kLine",
	trade_enableTrade: HOST + "/dapp/trade/enableTrade",
	ucenter_getUserWalletInfo: HOST + "/dapp/ucenter/getUserWalletInfo",
	ucenter_editWallet: HOST + "/dapp/ucenter/editWallet",
	ucenter_inviteCode: HOST + "/dapp/ucenter/inviteCode",
	ucenter_isSetTradePass: HOST + "/dapp/ucenter/isSetTradePass",
	ucenter_setTradePassword: HOST + "/dapp/ucenter/setTradePassword",
	suanli_getUserTaskAward: HOST + "/dapp/suanli/getUserTaskAward",
	suanli_doTaskAward: HOST + "/dapp/suanli/doTaskAward",
	suanli_suanliRule: HOST + "/dapp/suanli/suanliRule",
	home_rank: HOST + "/dapp/home/rank",
	home_indexNews: HOST + "/dapp/home/indexNews",
	shop_getCategory: HOST + "/dapp/shop/getCategory",
	shop_getGoodsByCategory: HOST + "/dapp/shop/getGoodsByCategory",
	banner_index: HOST + "/dapp/banner/posIndex",
	banner_taskcenter: HOST + "/dapp/banner/posTaskCenter",
	taskcenter_index: HOST + "/dapp/TaskCenter/index",
	taskcenter_getTaskAward: HOST + "/dapp/TaskCenter/getTaskAward",
	cash_withdrawPage: HOST + "/dapp/cash/withdrawPage",
	cash_withdraw: HOST + "/dapp/cash/withdraw",
	cash_withdrawList: HOST + "/dapp/cash/withdrawList",
	bonus_index: HOST + "/dapp/bonus/index",
	bonus_getBonus: HOST + "/dapp/bonus/getBonus",
	bbs_friendLists: HOST + "/dapp/bbs/friendLists",
	bbs_friend: HOST + "/dapp/bbs/friend",
	bbs_friendPool: HOST + "/dapp/bbs/friendPool",
	bbs_friendRank: HOST + "/dapp/bbs/friendRank",
	bbs_searchFriend: HOST + "/dapp/bbs/searchFriend",
	bbs_delFriend: HOST + "/dapp/bbs/delFriend",
	bbs_blacklist: HOST + "/dapp/bbs/blacklist",
	bbs_addToBlacklist: HOST + "/dapp/bbs/addToBlacklist",
	bbs_getOthersScoreLists: HOST + "/dapp/bbs/getOthersScoreLists",
	bbs_getFriendScoreLists: HOST + "/dapp/bbs/getFriendScoreLists",
	bbs_getScore: HOST + "/dapp/bbs/getScore",
	bbs_myLevel: HOST + "/dapp/bbs/myLevel",
	bbs_payVip: HOST + "/dapp/bbs/payVip",
	bbs_addFriend: HOST + "/dapp/bbs/addFriend",
	bbs_getTasteInfo: HOST + "/dapp/bbs/getTasteInfo",
	bbs_friendRequestLists: HOST + "/dapp/bbs/friendRequestLists",
	bbs_cancelBlacklist: HOST + "/dapp/bbs/cancelBlacklist",
	bbs_acceptFriendReq: HOST + "/dapp/bbs/acceptFriendReq",
	bbs_rejectFriendReqAndAddBlack: HOST + "/dapp/bbs/rejectFriendReqAndAddBlack",
	bbs_vipLists: HOST + "/dapp/bbs/vipLists",
	bbs_banner: HOST + "/dapp/banner/posBbs",
	bbs_checkConfirmLevel: HOST + "/dapp/bbs/checkConfirmLevel",
	bbs_publicWelfare: HOST + "/dapp/bbs/publicWelfare",
	bbs_totalPublicWelfare: HOST + "/dapp/bbs/totalPublicWelfare",
	bbs_userLevel: HOST + "/dapp/bbs/userLevel",
	bbs_saveTask: HOST + "/dapp/bbs/saveTask",
	oauth_oauth: HOST + "/dapp/oauth/oauth",
	oauth_checkMobile: HOST + "/dapp/oauth/checkMobile",
	oauth_bindMobile: HOST + "/dapp/oauth/bindMobile",
	order_payOrder: HOST + "/dapp/order/payOrder",
	ucenter_payForWallet: HOST + "/dapp/ucenter/payForWallet",
	shop_store: HOST + "/dapp/shop/store",
	shop_goodsDetail: HOST + "/dapp/shop/goodsDetail",
	shop_addCollection: HOST + "/dapp/shopCollection/addCollection",
	shop_delCollection: HOST + "/dapp/shopCollection/delCollection",
	shop_collectionLists: HOST + "/dapp/shopCollection/collectionLists",
	shop_isCollection: HOST + "/dapp/shopCollection/isCollection",
	shop_addToCart: HOST + "/dapp/createOrder/addToCart",
	shop_getShopCart: HOST + "/dapp/createOrder/getShopCart",
	//人民币商城创建订单
	shop_rmbCreateOrder: HOST + "/dapp/createOrder/createOrder",
	shop_setSubmitBuy: HOST + "/dapp/createOrder/setSubmitBuy",
	order_rmbGoodsOrderDetail: HOST + "/dapp/order/rmbGoodsOrderDetail",
	shop_addCollectionBatch: HOST + "/dapp/shopCollection/addCollectionBatch", //批量加入收藏
	shop_delCartBatch: HOST + "/dapp/createOrder/delCartBatch", //批量删除购物车中商品
	shop_delCollectionBatch: HOST + "/dapp/shopCollection/delCollectionBatch",
}

const USERS_KEY = 'USERS_KEY';

const getUser = function() {
	let ret = '';
	ret = uni.getStorageSync(USERS_KEY);
	if (!ret) {
		ret = '';
		return null;
	}
	return JSON.parse(ret);
}

const setUser = function(userInfo) {
	//let users = getUsers();
	var name = userInfo.name == null || userInfo.name == "" ? "未实名用户" : userInfo.name;
	let user = {
		mobile: userInfo.mobile,
		uid: userInfo.uid,
		token: userInfo.token,
		avatar: userInfo.avatar,
		name: name,
		openid: userInfo.openid,
	};
	uni.setStorageSync(USERS_KEY, JSON.stringify(user));
}

const removeUser = function(userInfo) {
	uni.removeStorageSync(USERS_KEY);
}

export default {
	API,
	getUser,
	setUser,
	removeUser,
	HOST,
	HTML_HOST,
	require_params,
	md5Key,
}
